package com.goodving.guli.bt.ui;

import android.content.Context;
import android.database.DataSetObserver;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.bt.eventbus.Event12HourUpdate;
import com.goodving.guli.bt.eventbus.EventAmPmUpdate;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.utility.Constants;
import com.goodving.guli.view.C4220a;

import de.greenrobot.event.EventBus;
import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.WheelViewAdapter;

/**
 * Created by john on 2015/12/9.
 */
public class PickAdapter implements WheelViewAdapter { //dm
    public static final int f9985a = 8388607;
    public static final String f9986b = "miui";
    public static final String f9987c = "normal";
    private static final String f9988d = "PickAdapter";
    private static final int f9989e = 16777215;
    private float f9990f;
    private float f9991g;
    private float f9992h;
    private int textColor3;
    private float f9994j;
    private int f9995k;
    private int f9996l;
    private boolean f9997m;
    private int textColor;
    private int textColor2;
    private int stopEnd;
    private int startEnd;
    private WheelView f10002r;
    private LayoutInflater mLayoutInflater;
    private Context f10004t;
    private int f10005u;
    private int f10006v;
    private String f10007w;
    private int f10008x;

    public PickAdapter(Context context, int i, int i2, WheelView wheelView, int i3, int i4) {
        this(context, i, i2, wheelView, i3, i4, false);
    }

    // i: the start year
    // i2: the end year
    // i3: text color
    // i4: text color 2
    // i5: text color 3
    public PickAdapter(Context context, int i, int i2, WheelView wheelView, int i3, int i4, int i5, boolean z, int i6, int i7, int i8, int i9) {
        this(context, i, i2, wheelView, i3, i4, i5, z, i6, i7, i8, i9, 1);
    }

    public PickAdapter(Context context, int i, int i2, WheelView wheelView, int i3, int i4, int i5, boolean z, int i6, int i7, int i8, int i9, int i10) {
        this.f9995k = 0;
        this.f10005u = 1;
        this.f10004t = context;
        this.startEnd = i;
        this.stopEnd = i2;
        this.f10002r = wheelView;
        this.mLayoutInflater = LayoutInflater.from(context);
        this.textColor = i3;
        this.textColor2 = i4;
        this.textColor3 = i5;
        this.f9997m = z;
        this.f9994j = TypedValue.applyDimension(1, (float) i6, context.getResources().getDisplayMetrics());
        this.f9990f = (float) i7;
        this.f9991g = (float) i8;
        this.f9992h = (float) i9;
        m14689b(i10);
        this.f9995k = (this.stopEnd - this.startEnd) + 1;
        this.f9996l = this.f9995k * (f9985a / this.f9995k);
    }

    public PickAdapter(Context context, int i, int i2, WheelView wheelView, int i3, int i4, boolean z) {
        this(context, i, i2, wheelView, i3, i4, C4220a.bm, z, 32, 11, 10, 9, 1);
    }

    private void m14682e() {
        this.f9995k = (this.stopEnd - this.startEnd) + 1;
        this.f9996l = this.f9995k * (f9985a / this.f9995k);
    }

    public int getItemsCount () { // m14683a
        return this.f9997m ? f9989e : this.f9995k;
    }

    class C1831do {
        TextView textView;
        final /* synthetic */ PickAdapter pickAdapter;

        private C1831do(PickAdapter dmVar) {
            this.pickAdapter = dmVar;
        }
    }


    public View getItem (int i, View view, ViewGroup viewGroup) { // m14684a
        View view2;
        int i2;
        view = (RelativeLayout) view;
        int i3 = i % this.f9995k;
        if (view == null) {
            view2 = f9987c.equals(this.f10007w) ?
                    (RelativeLayout) this.mLayoutInflater.inflate(R.layout.wheel_item_normal, null) :
                    (RelativeLayout) this.mLayoutInflater.inflate(R.layout.wheel_item_miui, null);
            C1831do c1831do = new C1831do(this);
            c1831do.textView = (TextView) view2.findViewById(R.id.content_txt);
            c1831do.textView.getLayoutParams().height = (int) this.f9994j;
            view2.setTag(c1831do);
        } else {
            view2 = view;
        }
        TextView textView = ((C1831do) view2.getTag()).textView;
        CharSequence format = String.format("%02d", new Object[]{Integer.valueOf((this.startEnd + i3) * this.f10005u)});
        int e = this.f10002r.getCurrentItem(); // m26808e();
        GuliLog.tracePrintInfo(f9988d, "index = " + i + ", realCurIndex =" + e + ", pos=" + i3);
        switch (this.f10006v) {
            case 9 /*9*/:
                i2 = this.startEnd + i3;
                if (i2 < 0) {
                    i2 += 24;
                }
                format = String.format("%02d", new Object[]{Integer.valueOf(i2)});
                break;
            case 16 /*16*/:
                i3 += this.startEnd;
                if (i3 == 0) {
                    format = Constants.VIA_REPORT_TYPE_SET_AVATAR;
                } else if (i3 > 12) {
                    format = String.format("%02d", new Object[]{Integer.valueOf(i3 - 12)});
                }
                if (e == i) {
                    EventBus.getDefault().post(new Event12HourUpdate(i3));
                    break;
                }
                break;
            case 17 /*17*/:
                format = i3 == 0 ? this.f10004t.getString(R.string.am) : this.f10004t.getString(R.string.pm);
                if (i == e) {
                    EventBus.getDefault().post(new EventAmPmUpdate(i3));
                    break;
                }
                break;
            case 18 /*18*/:
                if (i != 0) {
                    format = String.format("%d", new Object[]{Integer.valueOf((i3 + this.startEnd) * this.f10005u)}) + this.f10004t.getString(this.f10008x);
                    break;
                }
                GuliLog.tracePrintInfo(f9988d, "set close");
                format = this.f10004t.getString(R.string.state_close);
                break;
            case 19 /*19*/:
                format = "." + String.format("%01d", new Object[]{Integer.valueOf(i3 + this.startEnd)});
                break;
            case 20 /*20*/:
                format = String.format("%d", new Object[]{Integer.valueOf((i3 + this.startEnd) * this.f10005u)}) + this.f10004t.getString(this.f10008x);
                break;
        }
        textView.setText(format);
        i2 = (int) this.f9990f;
        if (i == e) {
            textView.setTextColor(this.textColor);
        } else if (i == e - 1 || i == e + 1) {
            i2 = (int) this.f9991g;
            textView.setTextColor(this.textColor2);
        } else {
            i2 = (int) this.f9992h;
            textView.setTextColor(this.textColor3);
        }
        textView.setTextSize((float) i2);
        return view2;
    }

    public View getEmptyItem (View view, ViewGroup viewGroup) {
        return null;
    } // m14685a

    public void m14686a(int i) {
        this.f10006v = i;
    }

    public void registerDataSetObserver (DataSetObserver dataSetObserver) { // m14687a
    }

    public void m14688a(String str) {
        this.f10007w = str;
    }

    public void m14689b(int i) {
        this.f10005u = i;
    }

    public void unregisterDataSetObserver (DataSetObserver dataSetObserver) { // m14690b
    }

    public boolean isNeedLoop () {
        return this.f9997m;
    } // m14691b

    public int getInitLoopBase () { // m14692c
        return this.f9996l;
    }

    public void m14693c(int i) {
        this.startEnd = i;
    }

    public int getBASE_BUNDLE   () { // m14694d
        return this.f9995k;
    }

    public void m14695d(int i) {
        this.stopEnd = i;
        m14682e();
        GuliLog.tracePrintInfo("Height", "setEnd: " + i + " base bundle = " + this.f9995k);
    }

    public void m14696e(int i) {
        this.f10008x = i;
    }
}
